﻿@model PagedList<RBS.Web.Hotel.Models.Dine.OrderViewModel>

@using RBS.Web.Hotel.Models.Dine
@using Webdiyer.WebControls.Mvc

<!--列表-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
    <tr>
        <th width="8%">选择</th> 
        <th align="left">订单状态</th>
        <th align="left">订单渠道</th>
        <th align="left">联系人</th>
        <th align="left">联系电话</th>
        <th align="right">订单总金额</th>
        <th align="center">就餐时间</th>
        <th align="left">吃饭人数</th>
        <th align="left">桌位</th>
       @* <th align="left">预定人</th>*@
        <th align="left">预订时间</th>

        <th width="10%">操作</th>
    </tr>
    @if (null != ViewData.Model)
    {
        foreach (var item in ViewData.Model)
        {
        <tr>
            <td align="center">
                <input type="checkbox" id="chkId" value="@item.OrderID" class="checkall" style="vertical-align: middle;" />
                <input id="hidId" type="hidden" value="@item.OrderID"/>
            </td>
           
            <td align="left">
                @Html.DisplayFor(modelItem => item.OrderState)
            </td>
            <td align="left">
                @Html.DisplayFor(modelItem => item.OrderChannel)
            </td>
            <td align="left">
                @Html.DisplayFor(modelItem => item.ContactUser)
            </td>
            <td align="left">
                @Html.DisplayFor(modelItem => item.ContactMobile)
            </td>
            <td align="right"> 
                   @Html.Raw(new RBS.Core.BLL.D_Order_Details().GetOrderMoney(item.OrderID).ToString("N2") ) &nbsp;
            </td>
            <td align="center">
                @(item.OrderTime.ToString("MM-dd HH:ss"))
            </td>
            <td align="left">
                @Html.DisplayFor(modelItem => item.DineNum)
            </td>
            <td align="left">
                @Html.DisplayFor(modelItem => item.DineTable)
            </td>
          
            <td align="left">
                @Html.DisplayFor(modelItem => item.CreateTime)
            </td>
            <td align="center">
                @Html.ActionLink("查看", "OrderDetail", new { id = item.OrderID, action = @RBS.Common.RBSEnums.ActionEnum.Edit })  
                @if(item.IsCanConfirm){
                    <a href="javascript:confirmOrder('@item.OrderID')">订单确认</a>
                }
                @if(item.IsCanCancel){
                    <a href="javascript:cancelOrder('@item.OrderID')">订单取消</a>
                }
                @if(item.IsCanCheckout){
                    <a href="javascript:checkoutOrder('@item.OrderID')">结帐</a>
                }
                @* @if (item.IsCanCheckIn)
                 {
                    <a href="javascript:checkinOrder('@item.OrderID')">就坐</a>
                 } *@
             
                @Html.ActionLink("打印单", "OrderPint","Print", new { orderid = item.OrderID },null)
            </td>
        </tr>
        }
    }
</table>
<!--/列表-->
<!--内容底部-->
<div class="line20">
</div>
<div class="pagelist">
    <div class="l-btns">
        <span>显示</span> <span>10 条/页</span><span>共 @Model.TotalPageCount 页 @Model.TotalItemCount 条记录，当前为第 @Model.CurrentPageIndex 页</span>
    </div>
    @Ajax.Pager(Model, new PagerOptions 
                        { 
                            PageIndexParameterName = "pageIndex", 
                            ShowGoButton = false, 
                            CurrentPagerItemWrapperFormatString = "<span class=\"current\">{0}</span>" ,
                            CssClass="default"
                        }, 
                        new MvcAjaxOptions
                        { 
                            UpdateTargetId="divOrderContainer",
                            HttpMethod="Post",
                            DataFormId = "searchForm"
                        })
</div>
<!--/内容底部-->

<script type="text/javascript">

    $(function () {
        $("#btnDelete").click(function () {
            var f_str = "";
            $(".ltable :checkbox[id='chkId']").each(function () {
                if (this.checked && this.value != "undefined") {
                    f_str += this.value + ',';
                }
            });
            $.dialog.confirm("删除记录后不可恢复，您确定吗？", function () {
                var url = '@Url.Action("CookbookDelete")?ids=' + f_str;
                $.ajax({
                    url: url,
                    type: "post",
                    dataType: 'json',
                    success: function (data) {
                        if (data.IsSuccess) {
                            //$.dialog.alert(data.Msg);
                            window.location.reload();
                            //loadPage(data.Data);
                        }
                        else {
                            //  $("#msgtip").text(data.Msg);
                            $.dialog.alert(data.Msg);
                        }
                    }
                });
            });
            return false;
        });

    });

    //确认订单
    var confirmOrder = function (orderId) {
        $.dialog.confirm("确定确认订单信息？", function () {
            $.post("/Dine/ConfirmOrder", { OrderId: orderId }, function (data) {
                if (data.IsSuccess) {
                    $.dialog.alert("订单确认成功！");
                    window.location.reload();
                } else {
                    $.dialog.alert("订单确认失败！");
                }
            })
        })
    }
    //取消订单
    var cancelOrder = function (orderId) {
        $.dialog.confirm("确定取消订单信息？", function () {
            $.post("/Dine/CancelOrder", { OrderId: orderId }, function (data) {
                if (data.IsSuccess) {
                    $.dialog.alert("订单取消成功！");
                    window.location.reload();
                } else {
                    $.dialog.alert("订单取消失败！");
                }
            })
        })
    }
    //结算订单
    var checkoutOrder = function(orderId) {
        $.dialog.confirm("确定结算订单信息？", function() {
           // newbooks = dialog("newbooks", "订单确认", "@Url.Action("OrderConfirmation")" + "?orderId=" + orderId);
            window.location.href = "@Url.Action("jiesuan","Sm")?orderid=" + orderId;
        });
    }; 
    var checkinOrder = function (orderId) {
        $.dialog.confirm("确定就坐吗？", function () {
            $.post("/Dine/CheckinOrder", { OrderId: orderId }, function (data) {
                if (data.IsSuccess) {
                    $.dialog.alert("就坐成功！");
                    window.location.reload();
                } else {
                    $.dialog.alert("就坐失败！");
                }
            })
        })
    }

    function dialog(id, title, url) {
        abc = $.dialog({
            id: id, lock: true, title: title, width: '710px', height: '520px', content: "url:" + url, ok: function () {
                this.reload();
            }
        });
        return abc;
    }

</script>